<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('categorys', function (Blueprint $table) {
            $table->id();
            $table->string('name', 255)->comment('分类名称');
            $table->string('image')->nullable()->comment('封面图片');
            $table->unsignedBigInteger('parent_id')->default(0)->comment('父级ID');
            $table->boolean('is_directory')->default(0)->comment('是否目录');
            $table->unsignedInteger('level')->default(0)->comment('层级');
            $table->string('path')->default('-')->comment('路径');
            $table->integer('page')->default(0)->comment('页码/排序');
            $table->string('isbn')->nullable()->comment('ISBN编号');
            $table->string('unit_main_name')->nullable()->comment('单元主名称');
            $table->string('unit_name')->nullable()->comment('单元副标题');
            $table->string('module')->nullable()->comment('模块文件名');
            $table->timestamps();

            // 索引
            $table->index(['parent_id', 'level'], 'idx_parent_level');
            $table->index('page', 'idx_page');
            $table->index('module', 'idx_module');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('categorys');
    }
};
